package alvarodelrosal.chat.server.modelo.chataction;

import alvarodelrosal.chat.server.modelo.ChatConnection;
import alvarodelrosal.chat.server.modelo.ChatServer;
import java.util.List;

public class ChatConnectedUsers implements ChatAction {

    @Override
    public String getName() {
        return "ConnectedUsers";
    }
    
    @Override
    public boolean needsAdminPrivileges() {
        return false;
    }

    @Override
    public boolean needsLogin() {
        return true;
    }
    
    @Override
    public String doAction(ChatConnection currentConnection, List<String> parameters) {
        StringBuilder builder = new StringBuilder("ConnectedUsers");
        List<ChatConnection> onlineUsers = ChatServer.onlineUsers();
        for (ChatConnection connection : onlineUsers) {
            builder.append("<:@:>");
            builder.append(connection.whoAmI().getUserId());
        }
        return builder.toString();
    }

}
